﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DbfDotNet.Core
{


//    _______________________
// 0 | Number of next        |  ^
// 1 | available block       |  |
// 2 | for appending data    | Header
// 3 | (binary)              |  |
//   |-----------------------|  |
// 4 | ( Reserved )          |  |
//   | Size of blocks      *1|  |
//   |                       |  |
// 7 |                       |  |
//   |-----------------------|  |
// 8 | DBF file name         |  |
//   | without extention     |  |
//   :                       :  |
//15 |                       |  |
//   |-----------------------|  |
//16 | Reserved   (00h)      |  | <-3 when Dbase 3
//   |-----------------------|  |
//17 | ( Reserved )          |  |
//18 |                       |  |
//19 |                       |  |
//   |-----------------------|  |
//20 | Block length in bytes |  |
//21 |                     *4|  |
//   |-----------------------|  |
//22 | ( Reserved )          |  |
//   |                       |  |
//   | (i.e. garbage)        |  |
//   :                       :  |
//   :                       :  |
//511|                       |  |
//   |=======================| _v_____
//  1|                       |  ^                 Used block
//   |                       |  ^           __  |=======================|
//   |                       |  |          /   0| ( Reserved )          |
//   :                       :  |         /    1|                       |
//   :                       :  |        /     2|  FFh FFh 08h 00h      |
//   |                       |  |       /      3|                       |
//511|                       |  |      /        |-----------------------|
//   |=======================| _|_____/        4| Length of memo field  |
//  1|                       |  |              5|                       |
//   :                       :  |              6|                       |
//   :                       :  |              7|                       |
//   |                       |  |               |-----------------------|
//511|                       | _|_____         8| Memo data           *2|
//   |=======================|  |     \         :                       :
//   |                       |  |      \       N|                       |
//   |                       |  |       \_____  |=======================|
//   |                       |  |
//   |                       | 512 Bytes
//   |                       | text blocks
//   :                       :  |
//   :                       :  |                 Unused block
//   :                       :  |           __  |=======================|
//   :                       :  |          /   0| Pointer to next free  |
//   :                       :  |         /    1| block                 |
//   :                       :  |        /     2|                       |
//   |                       |  |       /      3|                       |
//511|                       |  |      /        |-----------------------|
//   |=======================| _|_____/        4| Pointer to next used  |
//  1|                       |  |              5| block                 |
//   :                       :  |              6|                       |
//   :                       :  |              7|                       |
//   |                       |  |               |-----------------------|
//511|                       | _|_____         8| ( Reserved )          |
//   |=======================|  |     \         :                       :
//  1|                       |  |      \       N|                       |
//   |                       |  |       \_____  |=======================|
//   |                       |  |
//   :                       :  |
//   |                       |  |
//   |-----------------------| _|_____
//   | Field terminator (1Ah)|  |  ^
//   |-----------------------|  |  |Terminating field
//   | Field terminator (1Ah)|  |  |within the block *3
//   |-----------------------| _|__v__
//   : ( Unused )            :  |
//511|                       :  |
//   |=======================| _v_____
//   |                       |  ^
//   |                       |  |
//   |                       | 512 Bytes
//   |                       | text blocks
//   :                       :  |
//   :                       :  |
//   |                       |  |
//   |                       | _v_____
    //   |=======================|

#pragma warning disable 649
    [Record(FieldMapping = FieldMapping.ExplicitColumnsOnly)]
    internal sealed class DbtHeader
    {
        [Column(AdvancedType = AdvancedColumnType.UINT32)]
        public UInt32 FirstAvailableBlock; //Number of next available block for appending data (binary) 

        [Column(AdvancedType = AdvancedColumnType.DELAYED, Width = 12)] 
        public Byte[] Reserved1;

        [Column(AdvancedType = AdvancedColumnType.BYTE)]
        public Byte NdtVersion;

        [Column(AdvancedType = AdvancedColumnType.DELAYED, Width = 3)]
        public Byte[] Reserved2;

        [Column(AdvancedType = AdvancedColumnType.UINT16)]
        public UInt16 BlockLength;
    }


}
